<!DOCTYPE html>
<html>
<head>
	<title>我的签到</title>
	<meta charset="utf-8" />
	<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
	<link rel="stylesheet" href="/js/bootstrap/css/bootstrap.min.css">
	<script src="/js/jquery/jquery.min.js"></script>
	<link rel="stylesheet" href="/css/font/css/font-awesome.min.css" />
	<link rel="stylesheet" href="/css/reset.css" />
	<link rel="stylesheet" href="/css/myProfiles.css" />
	<script src="/js/plugins/jrender/jrender.js"></script>
	<link rel="stylesheet" href="/js/plugins/sign/css/public.css" />
	<link rel="stylesheet" href="/js/plugins/sign/css/signin.css" />
	<link rel="stylesheet" href="/js/plugins/dialog/dialog.css" />
	<script type="text/javascript" src="/js/plugins/sign/js/rili.js"></script>
	<script src="/js/plugins/dialog/dialog.min.js"></script>
</head>
<body>
<div class="nav-search">
	<a href="/mine/profiles.html">
		<span><i class="fa fa-angle-left fa-2x" ></i></span>
	</a>
</div>
<hr/>

<div class="top flex flex-align-end flex-pack-center flex-warp">
	<div class="out-1 flex flex-align-center flex-pack-center" id="signIn">
		<div class="out-2 flex flex-align-center flex-pack-center">
			<div class="signBtn">
				<strong id="sign-txt">签到</strong>
				<span>连续<em id="sign-count">0</em>天</span>
			</div>
		</div>
	</div>
	<div class="tips"></div>
</div>
<div class="Calendar">
	<div id="toyear" class="flex flex-pack-center">
		<div id="idCalendarPre">&lt;</div>
		<div class="year-month">
			<span id="idCalendarYear">2018</span>年<span id="idCalendarMonth">6</span>月
		</div>
		<div id="idCalendarNext">&gt;</div>
	</div>
	<table border="1px" cellpadding="0" cellspacing="0">
		<thead>
		<tr class="tou">
			<td>日</td>
			<td>一</td>
			<td>二</td>
			<td>三</td>
			<td>四</td>
			<td>五</td>
			<td>六</td>
		</tr>
		</thead>
		<tbody id="idCalendar">
		</tbody>
	</table>
</div>
<div style="text-align:center;margin:50px 0; font:normal 10px/20px 'MicroSoft YaHei';">
	<p>活动规则:签到一次加一积分,连续签到加两分,连续签到逢7的倍数,加的积分为5乘上该倍数,当倍数大于10时,积分统一为50</p>
	<p>*：<a href="http://sc.chinaz.com/" target="_blank">该活动本公司拥有唯一解释权</a></p>
</div>
<script language="JavaScript">
    //从本地session中取出缓存的对象,渲染到界面中
    var user = JSON.parse(sessionStorage.getItem("user"));
    var isSign = false;
    var myday = new Array(); //已签到的数组
    //         myday[0] = 1541125073
    //          myday[1] = "1542176104"
    //			myday[2] = "1525708800"
	var signCount = 0;
    $.get("/users/" + user.id + "/signTimes" , function (data) {
        $.each(data , function (index , ele) {
            var signTime = ele.modifyTime/1000;
            myday[index] = signTime;
        });
        if (data.length){
            signCount = data[0].signCount;
            $(".tips").html("本月签到" + data[0].signHistory +"天,请再接再厉!")
		} else {
            $(".tips").html("本月签到0天,请再接再厉!")
		}
    });


    setTimeout(function () {
        var cale = new Calendar("idCalendar", {
            qdDay: myday,
            onToday: function(o) {
                o.className = "onToday";
            },
            onSignIn: function (){
                $$("sign-txt").innerHTML = '已签到';
            },
            onFinish: function() {
                $$("sign-count").innerHTML = signCount //已签到次数
                $$("idCalendarYear").innerHTML = this.Year;
                $$("idCalendarMonth").innerHTML = this.Month; //表头年份

            }
        });
        $$("idCalendarPre").onclick = function() {
            cale.PreMonth();
        }
        $$("idCalendarNext").onclick = function() {
            cale.NextMonth();
        }
        //添加今天签到
        $$("signIn").onclick = function() {
            if(isSign == false) {
                var res = cale.SignIn();
                if(res == '1') {
                    $$("sign-txt").innerHTML = '已签到';
                    $.post("/users/"+user.id+"/signTimes" , function (data) {
                        //$$("sign-count").innerHTML = parseInt($$("sign-count").innerHTML) + 1;
                        var data = JSON.parse(data);
                        $$("sign-count").innerHTML = data.sign.signCount;
                        $(".tips").html("本月签到" + data.sign.signHistory +"天,请再接再厉!")
                        $(document).dialog({
                            type : 'confirm',
                            style: 'IOS',
                            titleText: "签到成功",
                            content: data.msg,
                            buttons: [
                                {
                                    name: '回到个人页面',
                                    callback: function() {
                                        location.href = "/mine/profiles.html";
                                    }
                                },
                                {
                                    name: '留在本页',
                                    callback: function() {
                                        //window.location.reload();
                                    }
                                }
                            ]
                        });
                    });
                    isSign = true;
                } else if (res == '2'){
                    $$("sign-txt").innerHTML = '已签到';
                    $(document).dialog({
                        type : 'confirm',
                        style: 'IOS',
                        titleText: "提示",
                        content: "今天已经签到了",
                        buttons: [
                            {
                                name: '确定',
                                callback: function() {
                                }
                            },
                        ]
                    });
                }
            } else {
                $(document).dialog({
                    type : 'confirm',
                    style: 'IOS',
                    titleText: "提示",
                    content: "今天已经签到了",
                    buttons: [
                        {
                            name: '确定',
                            callback: function() {
                            }
                        },
                    ]
                });
            }
        }
    },100)

</script>

</body>

</html>